$(document).ready(function() {
	var search_text = '[search_text]';
	if (typeof lang.search_text != 'undefined'){
		search_text = lang.search_text;
	}
	
	$("#search").focus(function(){
		if ($(this).val() == search_text){
			$(this).val('');
		}
	});
	
	$("#search").blur(function(){
		if ($(this).val() == ''){
			$(this).val(search_text);
		}
	});
	
	/* method to ignor the default value Istvan Gombos BoF*/
	jQuery.validator.addMethod( 
	  "defultNone", 
	  function(value, element) { 
		   return value !== element.defaultValue;
		  }	, 'Please enter a value.'
	); 
	/* method to ignor the default value Istvan Gombos EoF*/
	
	$(".dropdownSelector").msDropDown();
//	var selectBox = $("select#currencySelector").selectBoxIt().data("selectBoxIt");

	$('#languageSelector').change(function(){
		$.ajax({
            url: settings.base_url + lang.lang_key + '/main/get_country/' + $('#languageSelector option:selected').attr('lang_id'),
            dataType: 'json',
            type: 'POST',
            success: function(){
                window.location = $('#languageSelector').val();
            },
        });
	});
	$('#countrySelector').change(function(){
		window.location = settings.base_url + 'en/main/selectShippingCurrency/' + $(this).val() + '/' + $('#currencySelector').val();
	});	
	$('#currencySelector').change(function(){
		window.location = settings.base_url + 'en/main/selectShippingCurrency/' + $('#countrySelector').val() + '/' + $(this).val();
	});		
	$(".button").mousedown(function(){
		$(this).addClass("activ");
	});
	$(".button").mouseup(function(){
		$(this).removeClass("activ");
	});

	$("#cart-small-header-input").bind({
		  click: function(){
			  window.location =  settings.base_url + lang.lang_key + '/cart';
		  }
	 });
	
	
	if ($("#slider img").length) {
		$("#slider img").each(function(){
			$(this).attr('title',$("#slider_img_title").html());
			$(this).addClass('mainImage');
		});
		
		$("#slider_img_title").remove();
		
		$('#slider').nivoSlider({
	        effect: 'fade', // Specify sets like: 'fold,fade,sliceDown'
	        slices: 15, // For slice animations
	        boxCols: 8, // For box animations
	        boxRows: 4, // For box animations
	        animSpeed: 500, // Slide transition speed
	        pauseTime: 5000, // How long each slide will show
	        startSlide: 0, // Set starting Slide (0 index)
	        directionNav: false, // Next & Prev navigation
	        directionNavHide: true, // Only show on hover
	        controlNav: true, // 1,2,3... navigation
	        controlNavThumbs: false, // Use thumbnails for Control Nav
	        pauseOnHover: false, // Stop animation while hovering
	        manualAdvance: false, // Force manual transitions
	        prevText: 'Prev', // Prev directionNav text
	        nextText: 'Next', // Next directionNav text
	        randomStart: false, // Start on a random slide
	        beforeChange: function(){}, // Triggers before a slide transition
	        afterChange: function(){}, // Triggers after a slide transition
	        slideshowEnd: function(){}, // Triggers after all slides have been shown
	        lastSlide: function(){}, // Triggers when last slide is shown
	        afterLoad: function(){} // Triggers when slider has loaded
	    });
	}
	
	if ($("#carousel_slide").length){
		function mycarousel_initCallback(carousel)
		{
		    // Pause autoscrolling if the user moves with the cursor over the clip.
		    carousel.clip.hover(function() {
		        carousel.stopAuto();
		    }, function() {
		        carousel.startAuto();
		    });
		};
		
		jQuery('#carousel_slide').jcarousel({
			auto: 2,
			wrap: 'both',
	        scroll: 1,
	        visible: 4,
	        initCallback: mycarousel_initCallback
	    });
	}
	
	$("#search").keyup(function(e){
		if (e.keyCode == 13 && $(this).val() != ''){
			 $.ajax({
	            url: settings.base_url + lang.lang_key + '/product_list/get_url',
	            dataType: 'json',
	            type: 'POST',
	            data:{
	            	current_url: document.URL,
	            	type: 'search',
	            	value: $('#search').val()
	            },
	            success: function(data){
	                if (data.status){
	                    window.location = data.url;
	                }
	            },
	        });
		}
	});
	
	$("#search_price_btn").click(function(){
		var price_from = 0;
		var price_to = 0;
		
		if ($("#min_price").val() != ''){
			price_from = parseFloat($("#min_price").val());
		}
		if ($("#max_price").val() != ''){
			price_to = parseFloat($("#max_price").val());
		}

		$.ajax({
            url: settings.base_url + lang.lang_key + '/product_list/get_url',
            dataType: 'json',
            type: 'POST',
            data:{
            	current_url: document.URL,
            	type: 'price',
            	value:  price_from + "," + price_to
            },
            success: function(data){
                if (data.status){
                    window.location = data.url;
                }
            },
        });
		
	});
});

function showMore(selector,element){
	$('.additional-'+selector).each(function(i,el){
		if ($(el).hasClass('selected')){
			$(el).removeClass('additional-'+ selector);
		}
	});
	
	if ($('.additional-'+selector).is(":visible")){
		$(element).html("+" + lang.show_more);
	} else {
		$(element).html("-" + lang.show_less);
	}
	$('.additional-'+selector).toggle();
}

function getByPrice(interval,element){
	if (!$(element).parent().hasClass('selected')){
		$("#search-price").val(interval);
	} else {
		$("#search-price").val('');
	}
	$("#get-products-filter").submit();
}

function getByCategory(cat_id,element){
	if (!$(element).parent().hasClass('selected')){
		$("#search-category").val(cat_id);
	} else {
		$("#search-category").val('');
	}
	$("#get-products-filter").submit();
}

function getByMetal(prod_id,element){
	if (!$(element).parent().hasClass('selected')){
		$("#search-metal").val(prod_id);
	} else {
		$("#search-metal").val('');
	}
	$("#get-products-filter").submit();
}

function getByGem(gem,element){
	if (!$(element).parent().hasClass('selected')){
		$("#search-gem").val(gem);
	} else {
		$("#search-gem").val('');
	}
	$("#get-products-filter").submit();
}

function closeFilter(element){
	$(element).next().animate({height: 'toggle'});
	$(element).toggleClass('open closed');
}

function showFilters(element){
	$(element).parent().parent().hide()
	$(".supplimentar_filter").show();
}

